<?php
/**
 * Created by PhpStorm.
 * User: ewen
 * Date: 4/27/21
 * Time: 2:38 PM
 */

namespace app\common\model;


use think\Log;

class PartnerAccount extends Common
{

    protected $table = 'partner.partner_account';
//    // 设置当前模型的数据库连接
//    protected $connection = 'db_partner';

    /**
     * 查看用户是否是合伙人
     * @param $userID
     * @return int
     */
    public static function isPartner($userID)
    {
        $info = self::where(['aid' => $userID])->count();
        //  查看是否已经给过合伙人奖励
        $res = AssetFlow::where([
            'currency_id' => 1000002,
            'flow_type' => 101,
            'user_id' => $userID
        ])->count();
        if (!$res) {
            //  合伙人奖励
            $award = XkSystemRule::getAwardNum('partner');
            if ($award) {
                //  判断奖励是否溢出
                AssetFlow::getFlowTypeSumIncome($userID);
                $res = WebAssetAccount::coinAmountChange($userID, 'TXUSD', $award, self::TYPE_INC, 101);
            }
        }
        return $info ? 1 : 0;
    }
}